< previous page page_120 next page >

Page 120
intTimesClicked = intTimesClicked + 1

lblStatic.Caption = intTimesClicked
End Sub
analysis.gifBy using the keyword Static to declare the variable, youve created a variable that has a local scope but has a global lifetime.

Fixed-length Strings
When you declare string variables, you normally create a dynamic string, which means you can store approximately two billion characters in that string. Visual Basic automatically recalculates the storage requirements for the string as you add or subtract characters. Sometimes, however, you may require a string to have a fixed length. This comes in handy when dealing with fixed-length records in an ASCII text file, for example. You can create a fixed-length string by adding an asterisk (*) operator followed by a numeric value after the declaration of a string variable. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim strZipCode As String * 10
This statement initializes a string variable and fills it automatically with ten character zeros. Character zeros are a special null string value. Its not the space character, its actually a special type of ASCII value.
Once youve created this fixed-length string, it will always stay that size. If you put five characters into this string, the string will still have five character zeros on the end of it. If you attempt to place 15 characters into this string, the last five characters will be truncated.
Implicitly Declared Variables
In Visual Basic, its not absolutely necessary to explicitly declare variables before you use them. You can simply use a variable name on-the-fly. Consider the following code:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdOK_Click()
    intLoop = 1

    Print intLoop
End Sub

 
< previous page page_120 next page >

If you like this book, buy it!